package cn.kgc.springcloud.service.impl;

import cn.kgc.springcloud.client.ClazzClient;
import cn.kgc.springcloud.dao.GroupDao;
import cn.kgc.springcloud.entity.Clazz;
import cn.kgc.springcloud.entity.Group;
import cn.kgc.springcloud.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class GroupServiceImpl implements GroupService {
    @Autowired
    private GroupDao groupDao;
    @Autowired
    private ClazzClient clazzClient;
    @Override
    public List<Group> queryAll() {
        List<Group> groups = groupDao.queryAll();
        groups.forEach(group -> {
            String clazzId = group.getClazzId();
            Clazz clazz = clazzClient.getOne(Integer.parseInt(clazzId));
            group.setClazz(clazz);
        });
        return groups;
    }

    @Override
    public Group addOne(Group group) {
        group.setCreateDate(new Date());
        groupDao.addOne(group);
        return group;
    }

    @Override
    public Group selectOne(Integer id) {
        return groupDao.selectOne(id);
    }
}
